package com.xixibaby.core.login;


import com.xixibaby.core.SuperResponse;

/**
 * 登录流程
 * 1 数据验证
 * session缓存
 * 数据返回
 */
public abstract class LoginStragery<RES extends SuperResponse> {

    private LoginRule<RES> authRule;
    private SessionCache<RES> sessionCache;



    public void setAuthRule(LoginRule<RES> authRule) {
        this.authRule = authRule;
    }

    public void setSessionCache(SessionCache<RES> sessionCache) {
        this.sessionCache = sessionCache;
    }

    /**
     * 退出登录
     */
    public void loginOut(Long userId,int platform) {
        this.sessionCache.loginOut(userId,platform);
    }

    /**
     *
     * @param username 账号
     * @param password 密码
     * @param paltform 平台标志
     * @return 登录数据
     */
    public RES doLogin(String username, String password,int paltform){
        RES authorization =  this.authRule.authorization(username, password, paltform);
        this.sessionCache.cacheLoginInfo(authorization,paltform);
        return authorization;
    }

}
